<template>
  <page-header-wrapper>
    <a-card
      title="消息管理"
    >
      <div class="table-operator">
        <s-table
          bordered
          ref="table"
          size="middle"
          :row-key="(record) => record.id"
          :columns="msgColumns"
          :data="messageData"
        >
          <template slot="msg_type" slot-scope="text">
            <a-tag color="red">
              {{ msgOpts[text] }}
            </a-tag>
          </template>
          <template slot="action" slot-scope="text,record">
            <a-button size="small" type="primary" @click="toDetail(record.id)">详情</a-button>
          </template>
        </s-table>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
  import { STable } from '@/components'
  import { getMsgList } from '@/api/message'
  import col from '@/columns/message'

  export default {
    components: {
      STable
    },
    name: 'AllMessage',
    data () {
      return {
        msgColumns: col.message,
        messageData: parameters => {
          return getMsgList(Object.assign(parameters, this.queryParam)).then(res => {
            this.msgOpts = res.result.msg_opts
            return res.result
          })
        },
        queryParam: {},
        selectedRowKeys: [],
        activeType: 1,
        msgOpts: {}
      }
    },
    methods: {
      onSelectChange (selectedRowKeys) {
        this.selectedRowKeys = selectedRowKeys
      },
      onMsgType (e) {
        const app = this
        app.activeType = e.currentTarget.dataset.type
        app.queryParam['filter[type]'] = e.currentTarget.dataset.type
        app.$refs.table.refresh(true)
      },
      toDetail (id) {
        this.$router.push({ name: 'MessageDetail', params: { id } })
      }
    }
  }
</script>

<style scoped>
  .message-type {
    margin-bottom: 20px;
  }
  .message-type button {
    margin-right: 5px;
  }
</style>
